import tkinter as tk
import math

high = 0.2  # 默认0.2层高

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        frame = tk.Frame(self)
        frame.pack(padx=160, pady=90)

        # 标签和输入框
        self.label_fluency = tk.Label(frame, text="克重（g）:")
        self.label_fluency.pack(side="top")
        self.entry_fluency = tk.Entry(frame)
        self.entry_fluency.pack(side="top")



        # 计算按钮
        self.calculate_button = tk.Button(frame, text="计算", command=self.calculate)
        self.calculate_button.pack(side="top")

        # 输出结果标签
        self.result_label = tk.Label(frame, text="")
        self.result_label.pack(side="top")

        # 输出结果标签2
        self.result_label2 = tk.Label(frame, text="")
        self.result_label2.pack(side="top")

        # 输出结果标签3
        self.result_label3 = tk.Label(frame, text="")
        self.result_label3.pack(side="top")

        # 输出结果标签4
        self.result_label4 = tk.Label(frame, text="")
        self.result_label4.pack(side="top")

    def calculate(self):
        try:
            fluency = float(self.entry_fluency.get())
            fliment_price = fluency * 0.04
            FD_price = fliment_price + 10
            low_price = FD_price * 2
            high_price = FD_price * 2.5


            if fluency:
                # 计算价格
                self.result_label.config(text=f"材料价: {fliment_price:.2f}")
                self.result_label2.config(text=f"生产成本: {FD_price:.2f}")
                self.result_label3.config(text=f"底价: {low_price:.2f}")
                self.result_label4.config(text=f"标价: {high_price:.2f}")


            else:
                self.result_label.config(text="???")

        except ValueError:
            self.result_label.config(text="请输入有效的数字！")

if __name__ == '__main__':
    root = tk.Tk()
    app = Application(master=root)
    app.master.title("价格计算器")
    app.mainloop()
